﻿<%@ WebHandler Language="C#" Class="RBContainerAutoStartHandler" %>
/*Description: 热表自动开卡处理程序
'Copyright (c) : 通力凯顿（北京）系统集成有限公司
'Writer: Zhangrj 
'create Date:20230814
'Rewriter:
'Rewrite Date:
*/
using System;
using System.Web;
using BusinessRule.DTO;
using System.Web.SessionState;
using DatabaseAccess.DBUtility;
using System.Data.OracleClient;
using System.Data;
using System.Text;
using System.Linq;
using System.IO;
using Newtonsoft.Json;
using System.Collections.Generic;
using BusinessRule.Business;
using BusinessRule.IBusiness;
using BusinessRule.BusinessFactory;

public class RBContainerAutoStartHandler : IHttpHandler, IRequiresSessionState
{
    CurrentUserInfo m_UserInfo;
    uLMSCommonBusiness commonBusiness = new uLMSCommonBusiness();
    RbContainerBusiness rbBusiness = new RbContainerBusiness();
    //ApsContainerParam apsContainer = new ApsContainerParam();//页面提交数据
    private uLMSContainerIBusiness m_ContainerObj = uMESBusinessFactory.instance.GetuLMSContainerObject();
    public void ProcessRequest(HttpContext context)
    {
        try
        {
            var action = context.Request["action"].ToString();
            m_UserInfo = (CurrentUserInfo)context.Session["CurrentUserInfo"];
            if (m_UserInfo == null)
            {
                context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "登录过期，请重新登录" }));
                return;
            }
            switch (action)
            {
                case "GetApsShipNotStartContainerInfo": //获取未开卡的转工排产数据
                    GetApsShipNotStartContainerInfo(context);
                    break;
                case "GetSubContainerMakeingInfo": //获取已开卡的批次
                    GetSubContainerMakeingInfo(context);
                    break;
                case "OneKeyStartContainerInfo": //一键开卡
                    OneKeyStartContainerInfo(context);
                    break;
                case "GetContainerErrorInfo": //获取开卡出错日志
                    GetContainerErrorInfo(context);
                    break;
                case "ExportErrorInfoToExcel": //导出异常数据
                    ExportErrorInfoToExcel(context);
                    break;
                default:
                    context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "未知功能" }));
                    break;
            }
        }
        catch (Exception ex)
        {
            var result = new uMESProcessResult();
            result.Result = false;
            result.Message = ex.Message;
            context.Response.ContentType = "text/html";
            context.Response.Write(JsonConvert.SerializeObject(result));
        }
    }

    /// <summary>
    /// 导出批次开卡异常记录
    /// </summary>
    /// <param name="context"></param>
    public void ExportErrorInfoToExcel(HttpContext context)
    {
        string sql = "SELECT r.containername \"批次名\",r.workflownameandrev \"工艺\", r.workflowstepname \"工序名\",";
        sql += "r.errormessage \"异常原因\",r.createdate \"异常日期\"";
        sql += "FROM rbstartcontainererrorinfo r ORDER BY r.createdate DESC,r.containerid,r.workflowstepid";
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);
        byte[] bytes = uLMS_CommonFunction.DataTableExportToExcel(dt, "热表子卡创建异常记录");
        context.Response.Clear();
        context.Response.Buffer = true;
        context.Response.ClearHeaders();
        context.Response.ClearContent();
        context.Response.ContentType = "application/vnd.ms-excel";
        context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}{1}.xls", context.Server.UrlEncode("热表子卡创建异常记录"), DateTime.Now.ToString("yyyyMMddHHmmssffff")));
        context.Response.AddHeader("Content-Length", bytes.Length.ToString());
        context.Response.AddHeader("Content-Type", "UTF-8");
        context.Response.Charset = "UTF-8";
        context.Response.ContentEncoding = Encoding.UTF8;
        context.Response.BinaryWrite(bytes);
        context.Response.Flush();
        context.Response.Close();
    }

    /// <summary>
    /// 获取在制开卡数据
    /// </summary>
    /// <param name="context"></param>
    public void GetSubContainerMakeingInfo(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true };
        Dictionary<string, string> dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["params"].ToString());
        dic.Add("FactoryID", m_UserInfo.FactoryID);
        result = rbBusiness.GetSubContainerMakeingInfoByPage(dic);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 获取开卡出错日志
    /// </summary>
    /// <param name="context"></param>
    public void GetContainerErrorInfo(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true };
        Dictionary<string, string> dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["params"].ToString());
        dic.Add("FactoryID", m_UserInfo.FactoryID);
        result = rbBusiness.GetContainerErrorInfo(dic);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 获取转工未开卡数据
    /// </summary>
    /// <param name="context"></param>
    public void GetApsShipNotStartContainerInfo(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true };
        Dictionary<string, string> dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["params"].ToString());
        if (!string.IsNullOrWhiteSpace(dic["PlanStartDate"]))
        {
            dic["PlanStartDate"] = dic["PlanStartDate"] + " 00:00:00";
        }
        if (!string.IsNullOrWhiteSpace(dic["PlanEndDate"]))
        {
            dic["PlanEndDate"] = dic["PlanEndDate"] + " 23:59:59";
        }
        dic.Add("FactoryID", m_UserInfo.FactoryID);
        result = rbBusiness.GetApsPlanShipOutDatasByPage(dic);
        foreach (DataRow item in result.DBTable.Rows)
        {
            //查询工序的子工艺
            DataTable subWorkflowDt = commonBusiness.GetSubWorkflowInfo(new Dictionary<string, string> { { "WorkflowStepID", item["workflowstepid"].ToString() }, { "FactoryID", m_UserInfo.FactoryID } });
            if (subWorkflowDt.Rows.Count > 0)
            {
                item["subworkflowinfo"] = string.Format("{0}:{1}", subWorkflowDt.Rows[0]["subworkflowname"].ToString(), subWorkflowDt.Rows[0]["subworkflowrevision"].ToString());
                //查询子工艺最新的工艺
                var newestSubWorkflow = commonBusiness.GetWorkflowInfoByNameAndRev(new Dictionary<string, string>(){
                                                                                  {"WorkflowName",subWorkflowDt.Rows[0]["subworkflowname"].ToString()}
                                        }).AsEnumerable().OrderByDescending(row => row["workflowid"].ToString()).FirstOrDefault();
                string newestworkflowrev = newestSubWorkflow["workflowrevision"].ToString();
                if (!string.IsNullOrWhiteSpace(newestworkflowrev) && newestworkflowrev != subWorkflowDt.Rows[0]["subworkflowrevision"].ToString())
                {
                    item["newsubworkflowinfo"] = string.Format("{0}:{1}", subWorkflowDt.Rows[0]["subworkflowname"].ToString(), newestworkflowrev);
                }
                item["subworkflowtype"] = newestSubWorkflow["workflowtype"].ToString();
            }
        }
        result.DBTable.AcceptChanges();
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 一键开卡
    /// </summary>
    /// <param name="context"></param>
    public void OneKeyStartContainerInfo(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult();
        RBShipAutoStartContainerParam apsContainer = JsonConvert.DeserializeObject<RBShipAutoStartContainerParam>(context.Request["param"].ToString());
         result = rbBusiness.AutoStartContainerForShip(apsContainer, m_UserInfo);
        //try
        //{
        //    apsContainer = JsonConvert.DeserializeObject<ApsContainerParam>(context.Request["param"].ToString());
        //    if (rbBusiness.IsExistsSubContainer(apsContainer.ContainerID, apsContainer.WorkflowStepName))//验证是否存在子卡
        //    {
        //        result.Result = false; result.Message = "转工工序已存在子卡";
        //        context.Response.Write(JsonConvert.SerializeObject(result));
        //        return;
        //    }
        //    ContainerStartInfo containerBaseInfo = new ContainerStartInfo();
        //    rbBusiness.FillContainerDefaultInfo(ref containerBaseInfo, m_UserInfo.FactoryID);
        //    containerBaseInfo.ChildList = null;
        //    containerBaseInfo.MfgBatch = apsContainer.MfgBatch;
        //    containerBaseInfo.MfgOrder = apsContainer.MfgOrderName;
        //    containerBaseInfo.Qty = apsContainer.Qty;
        //    containerBaseInfo.IsSelfMfg = apsContainer.IsSelfMfg;
        //    containerBaseInfo.Factory = m_UserInfo.Factory;
        //    containerBaseInfo.CheckTechnique = "";//暂时为空
        //    containerBaseInfo.UOM = "件";//暂时指定
        //    containerBaseInfo.Team = "";//暂时为空
        //    containerBaseInfo.StartEmployee = m_UserInfo.EmployeeName;
        //    containerBaseInfo.Comment = "";
        //    containerBaseInfo.PlannedStartDate = apsContainer.PlanStartTime.ToString("yyyy-MM-ddTHH:mm:ss");
        //    containerBaseInfo.PlannedCompletionDate = apsContainer.PlanEndTime.ToString("yyyy-MM-ddTHH:mm:ss");
        //    containerBaseInfo.ContainerType = "2";//默认批量加工
        //    //设置批次的工艺信息
        //    Tuple<bool, string> res = SetContainerWorkflowInfo(ref containerBaseInfo);
        //    if (!res.Item1)
        //    {
        //        rbBusiness.InsertAutoStartErrorInfo(GetStartErrorInfo(res.Item2));//插入错误日志
        //        result.Result = res.Item1; result.Message = res.Item2;
        //        context.Response.Write(JsonConvert.SerializeObject(result));
        //        return;
        //    }
        //    //设置其他字段信息
        //    res = SetContainerBaseInfo(ref containerBaseInfo);
        //    if (!res.Item1)
        //    {
        //        rbBusiness.InsertAutoStartErrorInfo(GetStartErrorInfo(res.Item2));//插入错误日志
        //        result.Result = res.Item1; result.Message = res.Item2;
        //        context.Response.Write(JsonConvert.SerializeObject(result));
        //        return;
        //    }
        //    if (apsContainer.ContainerType == "3" || apsContainer.ContainerType == "7") //如果主制批次是带子序号或者单件单卡，都转换成批量带子序号
        //    {
        //        res = SetChildContainerInfo(ref containerBaseInfo);
        //        if (!res.Item1)
        //        {
        //            rbBusiness.InsertAutoStartErrorInfo(GetStartErrorInfo(res.Item2));//插入错误日志
        //            result.Result = res.Item1; result.Message = res.Item2;
        //            context.Response.Write(JsonConvert.SerializeObject(result));
        //            return;
        //        }
        //    }
        //    //增加批次属性
        //    AddContainerAttribute(ref containerBaseInfo);
        //    ServerHostInfo serverInfo = new ServerHostInfo();
        //    serverInfo.UserName = m_UserInfo.APIUserName;
        //    serverInfo.Password = m_UserInfo.APIPassword;
        //    containerBaseInfo.ServerHostInfo = serverInfo;
        //    //api创建批次
        //    Camstar.WebClient.WebServicesProxy.InSiteWebServices.ResultStatus tempResult = m_ContainerObj.StartContainer(containerBaseInfo);
        //    if (tempResult.IsError)
        //    {
        //        rbBusiness.InsertAutoStartErrorInfo(GetStartErrorInfo("开卡报错：" + tempResult.Message));//插入错误日志
        //        result.Result = false; result.Message = tempResult.Message;
        //        context.Response.Write(JsonConvert.SerializeObject(result));
        //        return;
        //    }
        //    //保存主卡子卡的对应关系
        //    res = SaveContainerSubContainer(containerBaseInfo);
        //    if (!res.Item1)
        //    {
        //        rbBusiness.InsertAutoStartErrorInfo(GetStartErrorInfo("开卡成功，" + res.Item2));//插入错误日志
        //        result.Result = res.Item1; result.Message = "开卡成功，" + res.Item2;
        //        context.Response.Write(JsonConvert.SerializeObject(result));
        //        return;
        //    }
        //    rbBusiness.DeleAutoStartErrorInfo(apsContainer.ContainerID, apsContainer.WorkflowStepID);//开卡成功，删除出错日志
        //    //返回保存成功
        //    result.Result = true; result.Message = "开卡成功";
        //}
        //catch (Exception ex)
        //{
        //    rbBusiness.InsertAutoStartErrorInfo(GetStartErrorInfo("开卡失败，原因：" + ex.Message));//插入错误日志
        //    result.Result = false; result.Message = "开卡失败，原因：" + ex.Message;
        //}
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

//    /// <summary>
//    /// 设置批次工艺相关信息
//    /// </summary>
//    /// <param name="containerBaseInfo"></param>
//    /// <returns></returns>
//    private Tuple<bool, string> SetContainerWorkflowInfo(ref ContainerStartInfo containerBaseInfo)
//    {
//        string message = string.Empty;
//        Dictionary<string, string> dic = new Dictionary<string, string>();
//        string strsql = string.Format("SELECT 1 FROM workflowstep w WHERE w.workflowstepid = '{0}' AND w.wipmsglabel = '子工艺'", apsContainer.WorkflowStepID);
//        if (DatabaseHelper.Query_ReturnDatTable(strsql).Rows.Count == 0)
//        {
//            message = string.Format("转工工序：{0}没有定义【子工艺】标识", apsContainer.WorkflowStepName);
//            return new Tuple<bool, string>(false, message);
//        }
//        //查询主制分厂工序的子工艺信息（热表工艺）
//        DataTable subWorkflowDt = commonBusiness.GetSubWorkflowInfo(new Dictionary<string, string> { { "WorkflowStepID", apsContainer.WorkflowStepID }, { "FactoryID", m_UserInfo.FactoryID } });
//        if (subWorkflowDt.Rows.Count == 0)
//        {
//            message = string.Format("转工工序：{0}未找到子工艺信息", apsContainer.WorkflowStepName);
//            return new Tuple<bool, string>(false, message);
//        }
//        //设置开始工序
//        var workflowStepDt = commonBusiness.GetWorkFlowSetpsByWorkflowID(subWorkflowDt.Rows[0]["subworkflowid"].ToString());
//        if (workflowStepDt.Rows.Count == 0)
//        {
//            message = string.Format("子工艺：{0}-{1}未找到工序信息", subWorkflowDt.Rows[0]["subworkflowname"].ToString(), subWorkflowDt.Rows[0]["subworkflowrevision"].ToString());
//            return new Tuple<bool, string>(false, message);
//        }
//        containerBaseInfo.BeginStep = workflowStepDt.Rows[0]["WORKFLOWSTEPNAME"].ToString();
//        //设置工艺信息
//        containerBaseInfo.MfgWorkflowName = subWorkflowDt.Rows[0]["subworkflowname"].ToString();
//        containerBaseInfo.MfgWorkflowRevision = subWorkflowDt.Rows[0]["subworkflowrevision"].ToString();
//        containerBaseInfo.WorkflowName = subWorkflowDt.Rows[0]["subworkflowname"].ToString();
//        containerBaseInfo.WorkflowRevision = subWorkflowDt.Rows[0]["subworkflowrevision"].ToString();
//        containerBaseInfo.MfgWorkflowuseROR = false;
//        containerBaseInfo.ProductuseROR = false;
//        DataTable subProductDt = commonBusiness.GetProductInfoByID(subWorkflowDt.Rows[0]["subproductid"].ToString());
//        if (subProductDt.Rows.Count > 0)
//        {
//            containerBaseInfo.ProductName = subProductDt.Rows[0]["PRODUCTNAME"].ToString();
//            containerBaseInfo.ProductRevision = subProductDt.Rows[0]["productrevision"].ToString();
//        }
//        //查询子工艺关联的子件号,可能一对多，系统处理，和主件号匹配
//        subProductDt = DatabaseHelper.Query_ReturnDatTable(string.Format(@"select pw.workflowid,pb.productname,p.productrevision from productworkflowmapping pw
//                                                                left join product p on p.productid=pw.productid
//                                                                left join productbase pb on pb.productbaseid=p.productbaseid
//                                                                where pw.workflowid='{0}'", subWorkflowDt.Rows[0]["subworkflowid"].ToString()));
//        if (subProductDt.Rows.Count > 0)
//        {
//            DataRow[] subProduct = subProductDt.Select(string.Format("productname like '{0}%'", apsContainer.ProductName));
//            if (subProduct.Length > 0)
//            {
//                containerBaseInfo.ProductName = subProduct[0]["PRODUCTNAME"].ToString();
//                containerBaseInfo.ProductRevision = subProduct[0]["productrevision"].ToString();
//            }
//        }
//        //查询子工艺最新的工艺
//        var newestSubWorkflow = commonBusiness.GetWorkflowInfoByNameAndRev(new Dictionary<string, string>(){
//                {"WorkflowName",subWorkflowDt.Rows[0]["subworkflowname"].ToString()}
//            }).AsEnumerable().OrderByDescending(row => row["workflowid"].ToString()).FirstOrDefault();
//        string newestworkflowrev = newestSubWorkflow["workflowrevision"].ToString();
//        if (!string.IsNullOrWhiteSpace(newestworkflowrev) && newestworkflowrev != containerBaseInfo.WorkflowRevision.ToString())
//        {
//            containerBaseInfo.MfgWorkflowRevision = newestworkflowrev;
//            containerBaseInfo.WorkflowRevision = newestworkflowrev;
//        }
//        return new Tuple<bool, string>(true, message);
//    }

//    /// <summary>
//    /// 设置批次的其他信息
//    /// </summary>
//    /// <param name="containerInfo"></param>
//    /// <returns></returns>
//    private Tuple<bool, string> SetContainerBaseInfo(ref ContainerStartInfo containerBaseInfo)
//    {
//        string sql = string.Format(@"SELECT coi.customobjectitemsdesc,coi.customobjectitemsname FROM customobject co 
//                        LEFT JOIN customobjectitems coi ON coi.customobjectid = co.customobjectid AND coi.isuse = 0
//                        LEFT JOIN workflow w ON w.workflowtype = coi.customobjectitemsname
//                        LEFT JOIN workflowbase wb ON wb.workflowbaseid = w.workflowbaseid 
//                        WHERE co.customobjectname = '热表工艺类型工区关系' AND co.isuse = 0 
//                        AND wb.workflowname = '{0}' AND w.workflowrevision = '{1}'", containerBaseInfo.WorkflowName, containerBaseInfo.WorkflowRevision);
//        DataTable dtDic = DatabaseHelper.Query_ReturnDatTable(sql);//查出工艺类型对应关系
//        if (dtDic.Rows.Count == 0)
//        {
//            return new Tuple<bool, string>(false, "配置项【热表工艺类型工区关系】未找到相应的工艺类型");
//        }
//        string[] objItem = dtDic.Rows[0]["customobjectitemsdesc"].ToString().Split(';');
//        if (objItem.Length < 2)
//        {
//            return new Tuple<bool, string>(false, "配置项【热表工艺类型工区关系】内容无效");
//        }
//        RbType rbType;
//        switch (objItem[0])
//        {
//            case "R":
//                rbType = RbType.R;
//                break;
//            case "B":
//                rbType = RbType.B;
//                break;
//            case "T":
//                rbType = RbType.T;
//                break;
//            default:
//                return new Tuple<bool, string>(false, "配置项【热表工艺类型工区关系】内容无效");
//        }
//        //验证配置项中的工区是否有效
//        DataTable dtWorkCenter = commonBusiness.GetWorkCenterByFacoryID(m_UserInfo.FactoryID, false);
//        if (dtWorkCenter.AsEnumerable().Where(p => p["WORKCENTERNAME"].ToString() == objItem[1]).Count() == 0)
//        {
//            return new Tuple<bool, string>(false, "配置项【热表工艺类型工区关系】中工区无效");
//        }
//        string prefix = containerBaseInfo.ProductName + "/";
//        Tuple<string, string> res = getContainerNos(rbType, prefix);//（item1:热表大批次，item2:热表批次号）
//        containerBaseInfo.ContainerName = prefix + res.Item2;//前缀+批次号
//        containerBaseInfo.TogetherFlag = prefix + res.Item2;
//        containerBaseInfo.WorkCenter = objItem[1];//工区（取工艺类型对应关系）
//        containerBaseInfo.RbTogetherflag = res.Item1;
//        containerBaseInfo.RbContainerType = int.Parse(((Enum)rbType).ToString("D")).ToString();
//        //获取父卡机型，并赋值给子卡
//        DataTable conFamily = rbBusiness.GetContainerProductFamily(apsContainer.ContainerID);
//        Dictionary<int, String> listFamily = new Dictionary<int, String>();
//        foreach (DataRow productfamily in conFamily.Rows)
//        {
//            listFamily.Add(int.Parse(productfamily["sequence"].ToString()), productfamily["productfamilyname"].ToString());
//        }
//        containerBaseInfo.ProductFamilyList = listFamily;
//        return new Tuple<bool, string>(true, "获取成功");
//    }

//    private enum RbType { R = 1, B = 2, T = 3 }

//    /// <summary>
//    /// 获取热表的大批次和批次号
//    /// </summary>
//    /// <param name="rbType">热表类型</param>
//    /// <param name="prefix">批次前缀</param>
//    /// <returns></returns>
//    private Tuple<string, string> getContainerNos(RbType rbType, string prefix)
//    {
//        int maxIndex = 0;
//        string rbTogetherflag = string.Format("{0}-{1}-", DateTime.Now.ToString("yyMM"), Enum.GetName(typeof(RbType), rbType));
//        //查询此机加卡（父卡）的子和父togetherFlag
//        string faTogetherFlags = string.Empty;
//        var faTogetherFlagDt = rbBusiness.GetRelativesFatogetherflag(apsContainer.TogetherFlag);
//        foreach (DataRow r in faTogetherFlagDt.Rows)
//        {
//            faTogetherFlags += "'" + r["faTogetherFlag"].ToString() + "',";
//        }
//        faTogetherFlags = faTogetherFlags.TrimEnd(',');
//        //查询机加大批次号和热表类型对应的热表大批次号
//        var subContainerDt = rbBusiness.GetSubContainer(new Dictionary<string, string>() { { "FaTogetherFlags", faTogetherFlags}, 
//        { "SubRbContainerType", int.Parse(((Enum)rbType).ToString("D")).ToString()} });
//        if (subContainerDt.Rows.Count > 0)
//        {
//            rbTogetherflag = subContainerDt.Rows[0]["RbTogetherflag"].ToString();
//        }
//        else
//        {
//            maxIndex = rbBusiness.GetNewestRbTogetherflag(rbTogetherflag);
//            rbTogetherflag += (++maxIndex).ToString("D4");
//        }
//        //查询最大批次号
//        maxIndex = rbBusiness.GetNewestContainerNo(prefix + rbTogetherflag + "-");
//        string rbContainerNo = rbTogetherflag + "-" + (++maxIndex).ToString("D2");//批次号
//        return new Tuple<string, string>(rbTogetherflag, rbContainerNo);
//    }

//    /// <summary>
//    /// 设置子序号
//    /// </summary>
//    /// <param name="containerBaseInfo"></param>
//    /// <returns></returns>
//    private Tuple<bool, string> SetChildContainerInfo(ref ContainerStartInfo containerBaseInfo)
//    {
//        bool res = true; string resMsg = "";
//        DataTable dtChildContainer = apsContainer.ContainerType == "3" ? rbBusiness.GetChildContainer(apsContainer.ContainerID, apsContainer.WorkflowStepID) : commonBusiness.GetTableInfo("container", "containerid", apsContainer.ContainerID);
//        //子序号赋值
//        DataTable childDt = new DataTable();
//        childDt.Columns.Add("ContainerName");
//        childDt.Columns.Add("Qty");
//        childDt.Columns.Add("ChildBeginStep");
//        childDt.Columns.Add("TogetherFlag");
//        childDt.Columns.Add("QualificationNum");
//        childDt.Columns.Add("RbContainerType");
//        foreach (DataRow item in dtChildContainer.Rows)
//        {
//            if (string.IsNullOrWhiteSpace(item["qualificationnum"].ToString()))
//            {
//                res = false;
//                resMsg = "主卡子序号不存在";
//                break;
//            }
//            var childRow = childDt.NewRow();
//            childRow["ContainerName"] = containerBaseInfo.ContainerName + item["qualificationnum"].ToString();
//            childRow["Qty"] = 1;
//            childRow["ChildBeginStep"] = containerBaseInfo.BeginStep;
//            childRow["TogetherFlag"] = containerBaseInfo.TogetherFlag;
//            childRow["QualificationNum"] = item["qualificationnum"].ToString();
//            childRow["RbContainerType"] = containerBaseInfo.RbContainerType;
//            childDt.Rows.Add(childRow);
//        }
//        containerBaseInfo.ChildList = childDt;
//        containerBaseInfo.ContainerType = "3";
//        return new Tuple<bool, string>(res, resMsg);
//    }

//    /// <summary>
//    /// 添加批次属性
//    /// </summary>
//    /// <param name="containerBase"></param>
//    void AddContainerAttribute(ref ContainerStartInfo containerBase)
//    {
//        DataTable userattributedt = new DataTable();
//        userattributedt.Columns.Add("Name");
//        userattributedt.Columns.Add("Value");

//        DataRow dr = userattributedt.NewRow();
//        dr["Name"] = "CheckTechnique";
//        dr["Value"] = containerBase.CheckTechnique;
//        userattributedt.Rows.Add(dr);

//        dr = userattributedt.NewRow();
//        dr["Name"] = "BeginStep";
//        dr["Value"] = containerBase.BeginStep;
//        userattributedt.Rows.Add(dr);

//        if (containerBase.MonthPlan != null && !String.IsNullOrWhiteSpace(containerBase.MonthPlan.ToString()))
//        {
//            dr = userattributedt.NewRow();
//            dr["Name"] = "monthPlanName";
//            dr["Value"] = containerBase.MonthPlan;
//            userattributedt.Rows.Add(dr);
//        }

//        if (containerBase.IsSelfMfg == "0")
//        {
//            dr = userattributedt.NewRow();
//            dr["Name"] = "材料牌号";
//            dr["Value"] = "";
//            userattributedt.Rows.Add(dr);

//            dr = userattributedt.NewRow();
//            dr["Name"] = "实发数/顺序号";
//            dr["Value"] = "";
//            userattributedt.Rows.Add(dr);

//            dr = userattributedt.NewRow();
//            dr["Name"] = "熔炉号母";
//            dr["Value"] = "";
//            userattributedt.Rows.Add(dr);

//            dr = userattributedt.NewRow();
//            dr["Name"] = "检验编号";
//            dr["Value"] = "";
//            userattributedt.Rows.Add(dr);

//            dr = userattributedt.NewRow();
//            dr["Name"] = "库房保管";
//            dr["Value"] = "";
//            userattributedt.Rows.Add(dr);

//            dr = userattributedt.NewRow();
//            dr["Name"] = "器材检验";
//            dr["Value"] = "";
//            userattributedt.Rows.Add(dr);

//            dr = userattributedt.NewRow();
//            dr["Name"] = "代料牌号";
//            dr["Value"] = "";
//            userattributedt.Rows.Add(dr);

//            dr = userattributedt.NewRow();
//            dr["Name"] = "代料规格";
//            dr["Value"] = "";
//            userattributedt.Rows.Add(dr);

//            dr = userattributedt.NewRow();
//            dr["Name"] = "代料单号";
//            dr["Value"] = "";
//            userattributedt.Rows.Add(dr);

//            dr = userattributedt.NewRow();
//            dr["Name"] = "平行作业单号";
//            dr["Value"] = "";
//            userattributedt.Rows.Add(dr);

//            dr = userattributedt.NewRow();
//            dr["Name"] = "平行作业工序";
//            dr["Value"] = "";
//            userattributedt.Rows.Add(dr);

//            dr = userattributedt.NewRow();
//            dr["Name"] = "顾客代表";
//            dr["Value"] = "";
//            userattributedt.Rows.Add(dr);
//        }
//        userattributedt.AcceptChanges();
//        containerBase.AttributeList = userattributedt;
//    }

//    /// <summary>
//    /// 保存主卡子卡对应关系
//    /// </summary>
//    /// <param name="containerBaseInfo"></param>
//    private Tuple<bool, string> SaveContainerSubContainer(ContainerStartInfo containerBaseInfo)
//    {
//        try
//        {
//            //获取下批次关联的工艺信息
//            DataTable subWorkflowDt = commonBusiness.GetWorkflowInfoByNameAndRev(new Dictionary<string, string>() { 
//                                        {"Rev",containerBaseInfo.MfgWorkflowRevision.ToString() },
//                                        {"WorkflowName",containerBaseInfo.MfgWorkflowName.ToString()}});
//            string subWorkflowId = subWorkflowDt.Rows[0]["workflowid"].ToString();
//            string subProcessNo = subWorkflowDt.Rows[0]["process_no"].ToString();
//            string subContainerId = commonBusiness.GetTableInfo("container", "containername", containerBaseInfo.ContainerName.ToString()).Rows[0]["containerid"].ToString();
//            List<ExcuteEntity> exuteEntitys = new List<ExcuteEntity>();
//            if (apsContainer.ContainerType == "3")
//            {
//                DataTable childContainer = rbBusiness.GetChildContainer(apsContainer.ContainerID, apsContainer.WorkflowStepID);
//                foreach (DataRow item in childContainer.Rows)
//                {
//                    ExcuteEntity exuteEntity = new ExcuteEntity("containersubcontainer", ExcuteEntity.ExcuteTypeEnum.insert);
//                    exuteEntity.ExcuteFileds = new List<FieldEntity>() {new FieldEntity("containerid", apsContainer.ContainerID, FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("workflowstepid",apsContainer.WorkflowStepID, FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("containersubcontainerid", Guid.NewGuid().ToString(), FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("createemployeeid", m_UserInfo.EmployeeID, FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("faqty", apsContainer.Qty, FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("WorkflowStepName", apsContainer.WorkflowStepName , FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("SubWorkflowID", subWorkflowId, FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("SubProcessNo",subProcessNo, FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("createdate",DateTime.Now, FieldEntity.FieldTypeEnum.DateTime),
//                                                                          new FieldEntity("subcontainerid", subContainerId, FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("childcontainerid",item["CONTAINERID"].ToString(), FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("isuse",0, FieldEntity.FieldTypeEnum.Numer )};
//                    exuteEntitys.Add(exuteEntity);
//                }
//            }
//            else
//            {
//                ExcuteEntity exuteEntity = new ExcuteEntity("containersubcontainer", ExcuteEntity.ExcuteTypeEnum.insert);
//                exuteEntity.ExcuteFileds = new List<FieldEntity>() {new FieldEntity("containerid", apsContainer.ContainerID, FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("workflowstepid",apsContainer.WorkflowStepID, FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("containersubcontainerid", Guid.NewGuid().ToString(), FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("createemployeeid", m_UserInfo.EmployeeID, FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("faqty", apsContainer.Qty, FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("WorkflowStepName", apsContainer.WorkflowStepName, FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("SubWorkflowID", subWorkflowId, FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("SubProcessNo",subProcessNo, FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("createdate",DateTime.Now, FieldEntity.FieldTypeEnum.DateTime),
//                                                                          new FieldEntity("subcontainerid", subContainerId, FieldEntity.FieldTypeEnum.Str),
//                                                                          new FieldEntity("isuse",0, FieldEntity.FieldTypeEnum.Numer )};
//                exuteEntitys.Add(exuteEntity);
//            }
//            DatabaseHelper.ExecuteDataByEntitys(exuteEntitys);
//            return new Tuple<bool, string>(true, "保存成功");
//        }
//        catch (Exception ex)
//        {
//            return new Tuple<bool, string>(false, "保存主卡子卡对应关系出错：" + ex.Message);
//        }
//    }

//    /// <summary>
//    /// 获取出错信息
//    /// </summary>
//    /// <param name="errorMsg"></param>
//    /// <returns></returns>
//    private Dictionary<string, string> GetStartErrorInfo(string errorMsg)
//    {
//        return new Dictionary<string, string> { { "ContainerID",apsContainer.ContainerID},
//                                                { "ContainerName",apsContainer.ContainerName},
//                                                { "WorkflowID",apsContainer.WorkflowID},
//                                                { "WorkflowNameAndRev",apsContainer.WorkflowInfo},
//                                                { "WorkflowstepID",apsContainer.WorkflowStepID},
//                                                { "WorkflowstepName",apsContainer.WorkflowStepName},
//                                                { "Message",errorMsg},
//                                                { "EmployeeID",m_UserInfo.EmployeeID}};
//    }

    ///// <summary>
    ///// 一键开卡参数
    ///// </summary>
    //public class ApsContainerParam
    //{
    //    // <summary>
    //    /// 件号
    //    /// </summary>
    //    public string ProductName { get; set; }
    //    /// <summary>
    //    /// 批次号
    //    /// </summary>
    //    public string ContainerName { get; set; }
    //    /// <summary>
    //    /// 批次类型
    //    /// </summary>
    //    public string ContainerType { get; set; }
    //    /// <summary>
    //    /// 批次ID
    //    /// </summary>
    //    public string ContainerID { get; set; }
    //    /// <summary>
    //    /// 工序ID
    //    /// </summary>
    //    public string WorkflowStepID { get; set; }
    //    /// <summary>
    //    /// 工艺ID
    //    /// </summary>
    //    public string WorkflowID { get; set; }
    //    /// <summary>
    //    /// 工艺名及版本
    //    /// </summary>
    //    public string WorkflowInfo { get; set; }
    //    /// <summary>
    //    /// 工序名
    //    /// </summary>
    //    public string WorkflowStepName { get; set; }
    //    /// <summary>
    //    /// 工序号
    //    /// </summary>
    //    public string SpecNo { get; set; }
    //    // <summary>
    //    /// 大批次
    //    /// </summary>
    //    public string TogetherFlag { get; set; }
    //    /// <summary>
    //    /// 批次型别
    //    /// </summary>
    //    public string MfgBatch { get; set; }
    //    /// <summary>
    //    /// 订单号
    //    /// </summary>
    //    public string MfgOrderName { get; set; }
    //    /// <summary>
    //    /// 是否自制批次
    //    /// </summary>
    //    public string IsSelfMfg { get; set; }
    //    /// <summary>
    //    /// 批次数量
    //    /// </summary>
    //    public string Qty { get; set; }
    //    /// <summary>
    //    /// 计划开始时间
    //    /// </summary>
    //    public DateTime PlanStartTime { get; set; }
    //    /// <summary>
    //    /// 计划结束时间
    //    /// </summary>
    //    public DateTime PlanEndTime { get; set; }
    //}

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}